package com.team.ssm_item_lj.service.impl;

import com.team.ssm_item_lj.entity.PromotionMaterials;
import com.team.ssm_item_lj.dao.PromotionMaterialsDao;
import com.team.ssm_item_lj.service.PromotionMaterialsService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import jakarta.annotation.Resource;

/**
 * 宣传材料表(PromotionMaterials)表服务实现类
 *
 * @author zhuxhenxin
 * @since 2024-12-05 10:44:29
 */
@Service("promotionMaterialsService")
public class PromotionMaterialsServiceImpl implements PromotionMaterialsService {
    @Resource
    private PromotionMaterialsDao promotionMaterialsDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public PromotionMaterials queryById(Integer id) {
        return this.promotionMaterialsDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param promotionMaterials 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<PromotionMaterials> queryByPage(PromotionMaterials promotionMaterials, PageRequest pageRequest) {
        long total = this.promotionMaterialsDao.count(promotionMaterials);
        return new PageImpl<>(this.promotionMaterialsDao.queryAllByLimit(promotionMaterials, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param promotionMaterials 实例对象
     * @return 实例对象
     */
    @Override
    public PromotionMaterials insert(PromotionMaterials promotionMaterials) {
        this.promotionMaterialsDao.insert(promotionMaterials);
        return promotionMaterials;
    }

    /**
     * 修改数据
     *
     * @param promotionMaterials 实例对象
     * @return 实例对象
     */
    @Override
    public PromotionMaterials update(PromotionMaterials promotionMaterials) {
        this.promotionMaterialsDao.update(promotionMaterials);
        return this.queryById(promotionMaterials.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.promotionMaterialsDao.deleteById(id) > 0;
    }
}
